package ru.papergames.battleserver.network.clientpackets.flashuser;

import org.apache.log4j.Logger;
import ru.common.util.Point3D;
import ru.papergames.battleserver.model.battle.AbstractBattle;
import ru.papergames.battleserver.model.battle.BattlePlayer;
import ru.papergames.battleserver.model.battle.BattlePlayerAction;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Alexander Troshanin
 */
public class BattleMoveBall extends AbstractBattleAction {

    private static final Logger log = Logger.getLogger(BattleMoveBall.class.getName());

    private List<Point3D> route;

    @Override
    protected void readImpl() {
        int routeSize = readH();
        route = new ArrayList<Point3D>(routeSize);
        for (int i=0; i<routeSize; i++) {
            route.add(new Point3D(readH(), readH()));
        }
    }

    @Override
    protected void runImplInternal(AbstractBattle battle, BattlePlayer battlePlayer) {
        if (log.isDebugEnabled()) {
            log.debug("Got battle action move ball, route: {" + route + "}");
        }
        battle.executeSynchronizedAction(battlePlayer, BattlePlayerAction.MOVE_BALL, new Object[] {route});
    }

    @Override
    public String getType() {
        return "[c] BattleMoveBall[" + BATTLE_MOVE_BALL_PACKET_ID + "]";
    }
}
